home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / WASTE 1.0a4 Distribution / WASTE Source / WASTEIntf.p < prev    next >
Text File  |  1994-05-02  |  14KB  |  439 lines

  1. unit WASTEIntf;
  2.  
  3. { WASTE PROJECT: }
  4. { Internal interface: constants, types and inline code }
  5.  
  6. { Copyright © 1993-1994 Marco Piovanelli }
  7. { All Rights Reserved }
  8.  
  9. interface
  10.     uses
  11.         LongCoords;
  12.  
  13.     const
  14.  
  15. { alignment styles }
  16.  
  17.         weFlushLeft = -2;
  18.         weFlushRight = -1;
  19.         weFlushDefault = 0;
  20.         weCenter = 1;
  21.         weJustify = 2;
  22.  
  23. { values for the edge parameter }
  24.  
  25.         kLeadingEdge = -1;
  26.         kTrailingEdge = 0;
  27.  
  28. { control character codes }
  29.  
  30.         kBackspace = 8;
  31.         kEOL = 13;
  32.         kArrowLeft = 28;
  33.         kArrowRight = 29;
  34.         kArrowUp = 30;
  35.         kArrowDown = 31;
  36.  
  37. { bit equates for QuickDraw styles }
  38.  
  39.         tsBold = 0;
  40.         tsItalic = 1;
  41.         tsUnderline = 2;
  42.         tsOutline = 3;
  43.         tsShadow = 4;
  44.         tsCondense = 5;
  45.         tsExtend = 6;
  46.  
  47. { bit equates for the tsFlags field of the WETextStyle record }
  48.  
  49.         tsTSMHilite = 4;                            { set if style run is part of active input area }
  50.         tsTSMSelected = 5;                        { set for selected raw/converted text }
  51.         tsTSMConverted = 6;                        { set for converted text, clear for raw text }
  52.         tsRightToLeft = 7;                            { reserved for future use }
  53.  
  54. { bit equates for the mode parameter in WESetStyle and WEContinuousStyle }
  55.  
  56.         kModeFont = 0;
  57.         kModeFace = 1;
  58.         kModeSize = 2;
  59.         kModeColor = 3;
  60.         kModeAddSize = 4;
  61.         kModeToggleFace = 5;
  62.         kModeReplaceFace = 6;
  63.         kModeFlags = 15;
  64.  
  65. { values for the mode parameter in WESetStyle and WEContinuousStyle }
  66.  
  67.         weDoFont = $0001;
  68.         weDoFace = $0002;
  69.         weDoSize = $0004;
  70.         weDoColor = $0008;
  71.         weDoAll = weDoFont + weDoFace + weDoSize + weDoColor;
  72.         weDoAddSize = $0010;
  73.         weDoToggleFace = $0020;
  74.         weDoReplaceFace = $0040;
  75.         weDoFlags = $8000;
  76.  
  77. { values for WEFeatureFlag action parameter }
  78.  
  79.         weBitClear = 0;                                { disables the specified feature }
  80.         weBitSet = 1;                                { enables the specified feature }
  81.         weBitTest = -1;                                { returns the current setting of the specified feature }
  82.  
  83. { bit equates for the flags field in the WE record }
  84. { bits 0..15 can be used to turn on and off specific features with WEFeatureFlag }
  85. { bits 16..31 are used internally and should not be modified }
  86.  
  87. { private flags }
  88.  
  89.         weFHasColorQD = 31;                    { Color QuickDraw is available }
  90.         weFHasTextServices = 30;                { Text Services Manager is available }
  91.         weFNonRoman = 29;                        { at least one non-Roman script is enabled }
  92.         weFDoubleByte = 28;                    { a double-byte script is installed }
  93.         weFBidirectional = 27;                    { reserved for future use }
  94.         weFUseDualCaret = 26;                    { reserved for future use }
  95.         weFCaretVisible = 24;                    { the caret is currently visible }
  96.         weFMouseTracking = 23;                { set internally during mouse tracking }
  97.         weFAnchorIsEnd = 22;                    { anchor offset is selEnd }
  98.         weFUseNullStyle = 21;                    { a null style is associated with the empty selection }
  99.         weFActive = 20;                            { we're active }
  100.  
  101. { public flags }
  102.  
  103.         weFDrawOffscreen = 11;                { draw text offscreen for smoother visual results }
  104.         weFUseTempMem = 10;                { use temporary memory for main data structures }
  105.         weFInhibitRecal = 9;                        { if set, recals and redraws are inhibited }
  106.         weFDragAndDrop = 8;                    { reserved for future use }
  107.         weFIntCutAndPaste = 7;                { reserved for future use }
  108.         weFOutlineHilite = 2;                    { frame selection range when text pane is inactive }
  109.         weFAutoScroll = 0;                        { automatically scroll text when cursor is outside pane }
  110.  
  111. { masks for setting the feature bits }
  112.  
  113.         weDoAutoScroll = $0001;                { 1 << weFAutoScroll }
  114.         weDoOutlineHilite = $0004;            { 1 << weFOutlineHilite }
  115.         weDoIntCutAndPaste = $0080;        { 1 << weFIntCutAndPaste }
  116.         weDoDragAndDrop = $0100;            { 1 << weFDragAndDrop }
  117.         weDoInhibitRecal = $0200;            { 1 << weFInhibitRecal }
  118.         weDoUseTempMem = $0400;        { 1 << weFUseTempMem }
  119.         weDoDrawOffscreen = $0800;        { 1 << weFDrawOffscreen }
  120.  
  121. { scrap types }
  122.  
  123.         kTypeText = 'TEXT';
  124.         kTypeStyles = 'styl';
  125.  
  126. { selectors for WEGetInfo/WESetInfo }
  127.  
  128.         weClickLoop = 'clik';
  129.         weLineArray = 'line';
  130.         wePort = 'port';
  131.         weRefCon = 'refc';
  132.         weRunArray = 'runa';
  133.         weScrollProc = 'scrl';
  134.         weStyleTable = 'styl';
  135.         weText = 'text';
  136.         weTSMDocumentID = 'tsmd';
  137.         weTSMPostUpdate = 'post';
  138.         weTSMPreUpdate = 'pre ';
  139.  
  140. { values for WEAllocate allocFlags parameter }
  141.  
  142.         kAllocClear = $0001;                        { clear handle after allocation }
  143.         kAllocTemp = $0002;                    { use temporary memory if available }
  144.  
  145. { other miscellaneous constants }
  146.  
  147.         kMinFontSize = 1;                            { minimum valid font size }
  148.         kMaxFontSize = maxint;                { maximum valid font size }
  149.         kOneToOneScaling = $00010001;    { 1:1 scaling ratio }
  150.  
  151.     type
  152.  
  153.         WEChars = packed array[0..999999] of Char;
  154.         WECharsPtr = ^WEChars;
  155.         WECharsHandle = ^WECharsPtr;
  156.  
  157. { WETextStyle is just a familiar TextStyle record as defined by TextEdit, where }
  158. { tsFace is redefined as SignedByte (rather than Style) so that the filler byte }
  159. { becomes "visible" from Pascal and can be used to store internal flags }
  160.  
  161.         WETextStyle = record
  162.                 tsFont: Integer;                        { font family ID }
  163.                 tsFace: SignedByte;                { QuickDraw style attributes }
  164.                 tsFlags: SignedByte;                { flags (for internal use only) }
  165.                 tsSize: Integer;                        { point size }
  166.                 tsColor: RGBColor;                    { absolute red-green-blue color }
  167.             end;  { WETextStyle }
  168.         WETextStylePtr = ^WETextStyle;
  169.  
  170.         WERunAttributes = record
  171.                 runHeight: Integer;                { run height (ascent + descent + leading) }
  172.                 runAscent: Integer;                { font ascent }
  173.                 case Integer of
  174.                     0: (
  175.                             tsFont: Integer;
  176.                             tsFace: SignedByte;
  177.                             tsFlags: SignedByte;
  178.                             tsSize: Integer;
  179.                             tsColor: RGBColor;
  180.                     );
  181.                     1: (
  182.                             runStyle: WETextStyle;
  183.                     );
  184.             end;  { WERunAttributes }
  185.         WERunAttributesPtr = ^WERunAttributes;
  186.  
  187.         WERunInfo = record
  188.                 runStart: LongInt;
  189.                 runEnd: LongInt;
  190.                 runAttrs: WERunAttributes;
  191.             end;  { WERunInfo }
  192.         WERunInfoPtr = ^WERunInfo;
  193.  
  194.         WEStyleScrapElement = record
  195.                 scrpStartChar: LongInt;
  196.                 scrpAttrs: WERunAttributes;
  197.             end;  { WEStyleScrapElement }
  198.         WEStyleScrapElementPtr = ^WEStyleScrapElement;
  199.         WEStyleScrapElementHandle = ^WEStyleScrapElementPtr;
  200.  
  201. { another "view" for the familiar TextEdit 'styl' Clipboard type }
  202.  
  203.         WEStyleScrap = record
  204.                 scrpNStyles: Integer;
  205.                 scrpStyleTab: array[0..0] of WEStyleScrapElement;
  206.             end;  { WEStyleScrap }
  207.         WEStyleScrapPtr = ^WEStyleScrap;
  208.         WEStyleScrapHandle = ^WEStyleScrapPtr;
  209.  
  210. { the purpose of the GrafPort1 declaration is to redefine the txFace field as SignedByte, }
  211. { rather than Style ( = set of StyleItem), to avoid using THINK Pascal runtime routines }
  212. { for set manipulation }
  213.  
  214.         GrafPort1 = record
  215.                 device: Integer;
  216.                 portBits: BitMap;
  217.                 portRect: Rect;
  218.                 visRgn: RgnHandle;
  219.                 clipRgn: RgnHandle;
  220.                 bkPat: Pattern;
  221.                 fillPat: Pattern;
  222.                 pnLoc: Point;
  223.                 pnSize: Point;
  224.                 pnMode: Integer;
  225.                 pnPat: Pattern;
  226.                 pnVis: Integer;
  227.                 txFont: Integer;
  228.                 txFace: SignedByte;
  229.                 filler: SignedByte;
  230.                 txMode: Integer;
  231.                 txSize: Integer;
  232.                 spExtra: Fixed;
  233.                 fgColor: LongInt;
  234.                 bkColor: LongInt;
  235.                 colrBit: Integer;
  236.                 patStretch: Integer;
  237.                 picSave: Handle;
  238.                 rgnSave: Handle;
  239.                 polySave: Handle;
  240.                 grafProcs: QDProcsPtr;
  241.             end;  { GrafPort1 }
  242.         GrafPtr1 = ^GrafPort1;
  243.  
  244.         QDEnvironment = record
  245.                 envPort: GrafPtr;
  246.                 envPen: PenState;
  247.                 envStyle: WETextStyle;
  248.                 envMode: Integer;
  249.             end;  { QDEnvironment }
  250.  
  251.         WEStyleScrapPair = record
  252.                 first: WEStyleScrapElement;
  253.                 second: WEStyleScrapElement;
  254.             end;  { WEStyleScrapPair }
  255.         WEStyleScrapPeek = ^WEStyleScrapPair;
  256.  
  257.         RunArrayElement = record
  258.                 runStart: LongInt;                        { offset to first character in style run }
  259.                 styleIndex: LongInt;                    { index into style table (high word currently unused) }
  260.             end;  { RunArrayElement }
  261.         RunArrayElementPtr = ^RunArrayElement;
  262.         RunArrayElementHandle = ^RunArrayElementPtr;
  263.  
  264.         RunArrayPair = record
  265.                 first: RunArrayElement;
  266.                 second: RunArrayElement;
  267.             end;  { RunArrayPair }
  268.         RunArrayPeek = ^RunArrayPair;    { useful to "peek" at a portion of the run array }
  269.  
  270.     const
  271.         kRunArrayMaxIndex = (maxLongInt div SizeOf(RunArrayElement)) - 1;
  272.  
  273.     type
  274.         RunArray = array[0..kRunArrayMaxIndex] of RunArrayElement;
  275.         RunArrayPtr = ^RunArray;
  276.         RunArrayHandle = ^RunArrayPtr;
  277.  
  278.         StyleTableElement = record
  279.                 refCount: LongInt;                    { reference count }
  280.                 info: WERunAttributes;                { style information }
  281.             end;  { StyleTableElement }
  282.         StyleTableElementPtr = ^StyleTableElement;
  283.         StyleTableElementHandle = ^StyleTableElementPtr;
  284.  
  285.     const
  286.         kStyleTableMaxIndex = (maxint div SizeOf(StyleTableElement)) - 1;
  287.  
  288.     type
  289.         StyleTable = array[0..kStyleTableMaxIndex] of StyleTableElement;
  290.         StyleTablePtr = ^StyleTable;
  291.         StyleTableHandle = ^StyleTablePtr;
  292.  
  293.         LineRec = record
  294.                 lineStart: LongInt;                    { offset to first character in line }
  295.                 lineOrigin: LongInt;                    { distance from destRect.top, in pixels }
  296.                 lineAscent: Integer;                    { maximum font ascent for this line, in pixels }
  297.                 lineSlop: Integer;                        { extra pixels needed to fill up the line }
  298.                 lineJustAmount: Fixed;                { normalized slop value for justification }
  299.             end;  { LineRec }
  300.         LinePtr = ^LineRec;
  301.         LineHandle = ^LinePtr;
  302.  
  303.         LinePair = record
  304.                 first: LineRec;
  305.                 second: LineRec;
  306.             end;  { LinePair }
  307.         LinePeek = ^LinePair;                    { useful to "peek" at a portion of the line array }
  308.  
  309.     const
  310.         kLineArrayMaxIndex = (maxLongInt div SizeOf(LineRec)) - 1;
  311.  
  312.     type
  313.         LineArray = array[0..kLineArrayMaxIndex] of LineRec;
  314.         LineArrayPtr = ^LineArray;
  315.         LineArrayHandle = ^LineArrayPtr;
  316.  
  317.         WERec = record
  318.                 port: GrafPtr;                                { graphics port }
  319.                 hText: Handle;                                { handle to the raw text }
  320.                 hLines: LineArrayHandle;                { handle to the line array }
  321.                 hStyles: StyleTableHandle;            { handle to the style table }
  322.                 hRuns: RunArrayHandle;                { handle to the style run array }
  323.                 textLength: LongInt;                        { length of raw text block }
  324.                 nLines: LongInt;                            { number of lines }
  325.                 nStyles: LongInt;                            { number of distinct styles in the style table }
  326.                 nRuns: LongInt;                            { number of style runs in the style run array }
  327.                 viewRect: LongRect;                        { view rectangle }
  328.                 destRect: LongRect;                        { destination rectangle }
  329.                 selStart: LongInt;                            { start of selection range }
  330.                 selEnd: LongInt;                            { end of selection range }
  331.                 flags: LongInt;                                { 32 bits of miscellaneous flags }
  332.                 caretTime: LongInt;                        { time of most recent caret xoring }
  333.                 clickTime: LongInt;                        { time of most recent click }
  334.                 clickLoc: LongInt;                            { byte offset of most recent click }
  335.                 anchorStart: LongInt;                    { anchor word start }
  336.                 anchorEnd: LongInt;                        { anchor word end }
  337.                 clickLoop: ProcPtr;                        { click loop callback }
  338.                 unused1: SignedByte;                    { unused }
  339.                 clickEdge: SignedByte;                    { edge of character hit by most recent click }
  340.                 unused2: SignedByte;                    { unused }
  341.                 firstByte: SignedByte;                    { first byte of a double-byte character }
  342.                 offscreenPort: GrafPtr;                    { offscreen graphics world }
  343.                 viewRgn: RgnHandle;                    { handle to the view region }
  344.                 scrollProc: ProcPtr;                        { scroll callback }
  345.                 clickCount: Integer;                        { multiple click count }
  346.                 alignment: Integer;                        { alignment style }
  347.                 refCon: LongInt;                            { reference value for client use }
  348.                 tsmReference: Ptr;                        { Text Services Manager document ID }
  349.                 tsmAreaStart: LongInt;                    { start of active inline input area }
  350.                 tsmAreaEnd: LongInt;                    { end of active inline input area }
  351.                 tsmPreUpdate: ProcPtr;                { called before handling a TSM updt event }
  352.                 tsmPostUpdate: ProcPtr;                { called after handling a TSM updt event }
  353.                 nullStyle: WERunAttributes;            { style for null selection }
  354.             end;  { WERec }
  355.         WEPtr = ^WERec;
  356.         WEHandle = ^WEPtr;
  357.  
  358.  
  359. { ****** ASSEMBLY ROUTINES DEFINED IN WASTEUTILS.LIB ****** }
  360.  
  361.     procedure _WEForgetHandle (var h: univ Handle);
  362.     function _WESetHandleLock (h: univ Handle;
  363.                                     lock: Boolean): Boolean;
  364.     procedure _WEBlockClr (blockPtr: Ptr;
  365.                                     blockSize: LongInt);
  366.     function _WEBlockCmp (block1, block2: Ptr;
  367.                                     blockSize: LongInt): Boolean;
  368.     function _WEInsertSlot (h: univ Handle;
  369.                                     element: univ Ptr;
  370.                                     insertAt: LongInt;
  371.                                     slotSize: LongInt): OSErr;
  372.     function _WERemoveSlot (h: univ Handle;
  373.                                     removeAt: LongInt;
  374.                                     slotSize: LongInt): OSErr;
  375.     procedure _WEReorder (var a, b: LongInt);
  376.  
  377.  
  378. { ****** USEFUL INLINE ASSEMBLY ****** }
  379.  
  380.     function %_NewHandle (blockSize: Size;
  381.                                     var h: Handle): OSErr;
  382.     inline
  383.         $225F,                                { movea.l (sp)+, a1 }
  384.         $201F,                                { move.l (sp)+, d0 }
  385.         $A122,                                { _NewHandle }
  386.         $3E80,                                 { move.w d0, (sp) }
  387.         $2288;                                { move.l a0, (a1) }
  388.  
  389.     function %_GetHandleSize (h: univ Handle): Size;
  390.     inline
  391.         $205F,                                 { movea.l (sp)+, a0 }
  392.         $A025,                             { _GetHandleSize }
  393.         $2E80,                                 { move.l d0, (sp) }
  394.         $6A02,                             { bpl.s *+4 }
  395.         $4297;                                { clr.l (sp) }
  396.  
  397.     function %_SetHandleSize (h: univ Handle;
  398.                                     blockSize: Size): OSErr;
  399.     inline
  400.         $201F,                                 { move.l (sp)+, d0 }
  401.         $205F,                                { movea.l (sp)+, a0 }
  402.         $A024,                             { _SetHandleSize }
  403.         $3E80;                                { move.w d0, (sp) }
  404.  
  405.     procedure %_BlockMoveData (sourcePtr, destPtr: univ Ptr;
  406.                                     byteCount: LongInt);
  407.     inline
  408.         $201F,                                 { move.l (sp)+, d0 }
  409.         $225F,                                 { movea.l (sp)+, a1 }
  410.         $205F,                                 { movea.l (sp)+, d0 }
  411.         $A22E;                                { _BlockMove, IMMED }
  412.  
  413.     procedure %_TextFace (face: Integer);
  414.     inline
  415.         $A888;                                { _TextFace }
  416.  
  417.     function %_Gestalt (selector: OSType;
  418.                                     var response: LongInt): OSErr;
  419.     inline
  420.         $225F,                                 { movea.l (sp)+, a1 }
  421.         $201F,                                 { move.l (sp)+, d0 }
  422.         $A1AD,                             { _Gestalt }
  423.         $3E80,                                 { move.w d0, (sp) }
  424.         $2288;                                { move.l a0, (a1) }
  425.  
  426.     procedure IgnoreBoolean (b: Boolean);
  427.     inline
  428.         $544F;                                { addq.w #2, sp }
  429.  
  430.     procedure IgnoreShort (w: Integer);
  431.     inline
  432.         $544F;                                { addq.w #2, sp }
  433.  
  434.     procedure IgnoreLong (l: LongInt);
  435.     inline
  436.         $584F;                                { addq.w #4, sp }
  437.  
  438. implementation
  439. end.